package org.wattdepot.cli.commands;

import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;

/**
 * This class tests the carbon emitted command of the 
 * CommandLineInterface's actual commands.
 * @author David Mau
 */
public class TestCommandCarbonEmitted {

  /**
   * Test normal operation of the carbon emitted command.
   * Unfortunately, we don't know any known data for this command...
   */
  //@Test
  //public void testCarbonEmitted() {

  //}

  /**
   * Test bad time stamp detection for the carbon emitted command.
   */
  @Test
  public void testEnergyUsageBadTime() {
    // Create a new carbon emitted command object.
    CarbonEmittedCommand command = new CarbonEmittedCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_WAIAU", "HAHAHA", "2009-11-29", "max" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );
    
    // Check to see if the correct error returned
    assertTrue("Checking for correct response to a bad timestamp for first time", 
        sourceOutput.contains(WattDepotCliCommand.badTimeStamp));

    // Ready another test for bad timestamp detection.
    args = Arrays.asList( "SIM_KAHE", "2009-11-29", "OOPS", "min" );
    
    // Get the output from the command
    sourceOutput = command.doCommand( args );
    
    // Check to see if the correct error returned
    assertTrue("Checking for correct response to a bad timestamp for second time", 
        sourceOutput.contains(WattDepotCliCommand.badTimeStamp));
  }

  
  /**
   * Test bad source detection for the carbon emitted command.
   */
  @Test
  public void testEnergyUsageBadSource() {
    // Create a new carbon emitted command object.
    CarbonEmittedCommand command = new CarbonEmittedCommand(null);
    
    // Create a new List to store the args
    List<String> args = Arrays.asList( "WIND", "2009-10-01", "2009-11-01", "max" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );
    
    // Check to see if the correct error returned
    assertTrue("Checking for correct response to a bad source", 
        sourceOutput.contains(WattDepotCliCommand.resourceNotFound));
  }

  /**
   * Test bad option given for statistic for the carbon emitted command.
   */
  @Test
  public void testEnergyUsageBadStatistic() {
    // Create a new carbon emitted command object.
    CarbonEmittedCommand command = new CarbonEmittedCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_HONOLULU", "2009-09-01", "2009-10-01", "average" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );
    
    // Check to see if the correct error returned
    assertTrue("Checking for correct response to a bad statistic", 
        sourceOutput.contains(WattDepotCliCommand.minOrMax));
    
  }

  /**
   * Test a bad set of start and end dates given for the carbon emitted command.
   */
  @Test
  public void testEnergyUsageBadStartAndEndDates() {
    // Create a new carbon emitted command object.
    CarbonEmittedCommand command = new CarbonEmittedCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_IPP", "2009-05-01", "2009-04-01", "max" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );
    
    // Check to see if the correct error returned
    assertTrue("Checking for correct response to a bad set of start and end dates", 
        sourceOutput.contains(WattDepotCliCommand.endDateBeforeStartDate));
  }
  
  /**
   * Tests to see if the carbon emitted command can handle excess arguments.
   */
  @Test
  public void testExcessArguments() {
    // Create a new carbon emitted command object.
    CarbonEmittedCommand command = new CarbonEmittedCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1", "2", "3", "4", "5");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking excess carbon emitted argument handling", 
        sourceOutput.contains(WattDepotCliCommand.tooManyArguments));
  }
  
  /**
   * Tests to see if the carbon emitted command can handle not enough arguments.
   */
  @Test
  public void testFewArguments() {
    // Create a new carbon emitted command object.
    CarbonEmittedCommand command = new CarbonEmittedCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking carbon emitted handling not enough arguments", 
        sourceOutput.contains(WattDepotCliCommand.missingArguments));
  }
}
